package com.example.qxfw.dataBaseManager.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.example.qxfw.common.entity.CountyPoint;
import com.example.qxfw.common.entity.YbzzForecaststation;
import com.example.qxfw.common.entity.qx.SmallScaleStation;
import com.example.qxfw.common.entity.qx.SpecialSrvStation;
import com.example.qxfw.common.entity.qx.TownshipStation;
import com.example.qxfw.common.mapper.*;
import com.example.qxfw.dataBaseManager.service.QxxxzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/************************************
 *
 * @author : HuangDeYin Jolly
 * @since : JDK 11
 * @Date : 2023/7/6  星期四   16:35
 * @description : 此类用来
 ***************************************/
@Service
public class QxxxzServiceImpl implements QxxxzService {

    @Autowired
    private SmallscaleStationMapperXml smallscaleStationMapperXml;

    @Autowired
    private SpecialSrvStationMapperXml specialSrvStationMapperXml;

    @Autowired
    private CoMapper<CountyPoint> countyPointCommonMapper;

    @Autowired
    private TownshipStationMapperXml townshipStationMapperXml;

    @Autowired
    private YbzzForecaststationMapperXml ybzzForecaststationMapperXml;

    @Override
    public List<SmallScaleStation> querySelect(String province, String city) {
        return this.smallscaleStationMapperXml.selectData("distinct city", "smallscale_station", "province = '" + province + "' and city like '" + city + "%'", null, null);
    }

    @Override
    public List<SmallScaleStation> selectDistinct(String city) {
        return this.smallscaleStationMapperXml.selectData("distinct county", "smallscale_station", "city = '" + city + "'", null, null);
    }

    @Override
    public List<SmallScaleStation> selectQuery(final SmallScaleStation smallScaleStation) {
        return this.smallscaleStationMapperXml.selectList(new LambdaQueryWrapper<SmallScaleStation>()
                .isNotNull(SmallScaleStation::getStationid)
                .like(StringUtils.isNotBlank(smallScaleStation.getCity()), SmallScaleStation::getCity, smallScaleStation.getCity())
                .like(StringUtils.isNotBlank(smallScaleStation.getCounty()), SmallScaleStation::getCounty, smallScaleStation.getCounty())
                .like(StringUtils.isNotBlank(smallScaleStation.getTown()), SmallScaleStation::getTown, smallScaleStation.getTown())
                .like(StringUtils.isNotBlank(smallScaleStation.getStationname()), SmallScaleStation::getStationname, smallScaleStation.getStationname())
                .like(StringUtils.isNotBlank(smallScaleStation.getStationid()), SmallScaleStation::getStationid, smallScaleStation.getStationid())
                .orderByAsc(SmallScaleStation::getStationid)
        );
    }

    @Override
    public Integer addSmallScaleStation(final SmallScaleStation smallScaleStation) {

        return this.smallscaleStationMapperXml.insert(smallScaleStation);
    }

    @Override
    public Integer updateSmallScaleStation(final SmallScaleStation smallScaleStation) {
        return this.smallscaleStationMapperXml.update(smallScaleStation, new LambdaUpdateWrapper<SmallScaleStation>().eq(SmallScaleStation::getStationid, smallScaleStation.getStationid()));
    }

    @Override
    public List<SmallScaleStation> selectById(final SmallScaleStation smallScaleStation) {
        return this.smallscaleStationMapperXml.selectList(new LambdaQueryWrapper<SmallScaleStation>()
                .eq(StringUtils.isNotBlank(smallScaleStation.getStationid()), SmallScaleStation::getStationid, smallScaleStation.getStationid()));
    }

    @Override
    public Integer deleteSmallScaleStation(final String stationid) {
        return this.smallscaleStationMapperXml.delete(new LambdaQueryWrapper<SmallScaleStation>()
                .eq(SmallScaleStation::getStationid, stationid));
    }

    @Override
    public List<SpecialSrvStation> querySpecialSrvStation(final String column, String query, final String city) {
        return this.specialSrvStationMapperXml.queryDistinct(column, query, city, null, null);
    }

    @Override
    public List<CountyPoint> queryDistinctCountyPoint(final String column) {
        return this.countyPointCommonMapper.selectData(column, "county_point", null, null, null);
    }

    @Override
    public List<SpecialSrvStation> queryAllSpecialSrvStation() {
        return this.specialSrvStationMapperXml.selectList(null);
    }

    @Override
    public List<SpecialSrvStation> queryLikeSpecialSrvStation(SpecialSrvStation specialSrvStation) {
        return this.specialSrvStationMapperXml.query(specialSrvStation);
    }

    @Override
    public List<SpecialSrvStation> queryStationIdFromSpecialSrvStation(final String stationId, final String flag) {
        return this.specialSrvStationMapperXml.selectList(new LambdaQueryWrapper<SpecialSrvStation>()
                .eq(StringUtils.isNotBlank(stationId), SpecialSrvStation::getStationid, stationId)
                .eq(StringUtils.isNotBlank(flag), SpecialSrvStation::getFlag, flag));
    }

    @Override
    public Integer saveSpecialSrvStation(final SpecialSrvStation specialSrvStation) {
        return this.specialSrvStationMapperXml.insertSelective(specialSrvStation);
    }

    @Override
    public Integer updateSpecialSrvStation(final SpecialSrvStation specialSrvStation) {
        return this.specialSrvStationMapperXml.updateById(specialSrvStation);
    }

    @Override
    public Integer deleteSpecialSrvStation(final String stationId) {
        return this.specialSrvStationMapperXml.deleteById(stationId);
    }

    @Override
    public List<TownshipStation> queryTownShipStationLikeCity(final String city) {
        return this.townshipStationMapperXml.selectList(new LambdaQueryWrapper<TownshipStation>()
                .like(StringUtils.isNotBlank(city), TownshipStation::getCity, city));
    }

    @Override
    public List<TownshipStation> selectStationId(final String stationId) {
        return this.townshipStationMapperXml.selectList(new LambdaQueryWrapper<TownshipStation>()
                .eq(StringUtils.isNotBlank(stationId), TownshipStation::getStationid, stationId));
    }

    @Override
    public Integer saveTownShipStation(final TownshipStation townshipStation) {
        return this.townshipStationMapperXml.insert(townshipStation);
    }

    @Override
    public Integer updateTownShipStation(final TownshipStation townshipStation) {
        return this.townshipStationMapperXml.updateById(townshipStation);
    }

    @Override
    public Integer deleteTownShipStation(final String stationId) {
        return this.townshipStationMapperXml.delete(new LambdaQueryWrapper<TownshipStation>()
                .eq(TownshipStation::getStationid, stationId));
    }

    @Override
    public List<YbzzForecaststation> selectDistinct(String column, String order, Integer limit) {
        return this.ybzzForecaststationMapperXml.selectDistinct(column, order, limit);
    }

    @Override
    public List<YbzzForecaststation> selectAllYbzzForecStation() {
        return this.ybzzForecaststationMapperXml.selectList(null);
    }

    @Override
    public List<YbzzForecaststation> selectByStationIdYbzzForecStation(String stationId) {
        return this.ybzzForecaststationMapperXml.selectByStationId(stationId);
    }

    @Override
    public Integer saveYbzzForecaststation(final YbzzForecaststation ybzzForecaststation) {
        return this.ybzzForecaststationMapperXml.insertSelective(ybzzForecaststation);
    }

    @Override
    public Integer updateYbzzForecaststation(final YbzzForecaststation ybzzForecaststation) {
        String stationid = ybzzForecaststation.getStationid();
        ybzzForecaststation.setStationid(null);
        return ybzzForecaststationMapperXml.update(ybzzForecaststation, new LambdaUpdateWrapper<YbzzForecaststation>()
                .eq(YbzzForecaststation::getStationid, stationid));
    }

    @Override
    public Integer deleteYbzzForecaststation(final String stationId) {
        return this.ybzzForecaststationMapperXml.deleteById(stationId);
    }

    @Override
    public List<SmallScaleStation> querySmallScaleStation(final String stationId, final String stationName, final String city, final String county) {
        return this.smallscaleStationMapperXml.querySmallScaleStation(stationId, stationName, city, county);
    }
}
